package app.qrcode.browser.ykpixabay.ui.searchpic

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import app.qrcode.browser.ykpixabay.logic.Repository
import app.qrcode.browser.ykpixabay.logic.model.Hits

/**
 * Created by YiGo on 2022/4/18.
 */
class ViewPicViewModel : ViewModel() {

    private val searchLiveData = MutableLiveData<String>()

    val picLiveData = Transformations.switchMap(searchLiveData) { query ->
        Repository.searchPic(query)
    }

    val picList = ArrayList<Hits>()

    fun searchPic(query: String) {
        searchLiveData.value = query
    }
}